/**
 * 
 */
package com.me.brainlessbirds.actors;

import java.util.HashMap;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Timer.Task;
import com.me.brainlessbirds.actors.interfaces.Collidable;
import com.me.brainlessbirds.actors.interfaces.SurvivorCollidable;
import com.me.brainlessbirds.actors.interfaces.ZombieCollidable;
import com.me.brainlessbirds.actors.skills.Skill;

/**
 * @author Maxens Dubois
 *         GameObject are drawable objects in game scene
 *         With TextureRegion
 *         Which can take damage ,die ,move, have HP and Collision
 *         Got skills
 *         DOES NOT ATTACK AND MOVE !!
 */
public abstract class GameObject extends Actor implements Collidable, ZombieCollidable, SurvivorCollidable
{
	protected float									speed				= 0.0f;
	protected float									life				= 0.0f;
	protected TextureRegion							rgn					= new TextureRegion();
	protected float									destructionDelay	= 0.01f;
	// comme on a pas d'animation autant ne rien mettre en duree de destruction

	/*
	 * Some Skills
	 */
	//protected final ArrayList<Skill> skillArray = new ArrayList<Skill>();
	public HashMap<Class<? extends Skill>, Skill>	skillMap			= new HashMap<Class<? extends Skill>, Skill>();

	public void updateSkillsCooldown()
	{
		for (Skill skill : this.skillMap.values())
		{
			skill.updateCooldown();
		}
	}

	public void destroy(Task callbackTask)
	{
		Timer timer = new Timer();
		timer.scheduleTask(callbackTask, destructionDelay);
	}

	public float getLife()
	{
		return this.life;
	}

	public void takeDamage(float damageAmount)
	{
		life -= damageAmount;
	}

	public float getSpeed()
	{
		return this.speed;
	}

	@Override
	public boolean collide(GameObject actor)
	{
		if (((this.getX() + this.getWidth() > actor.getX()) && (this.getX() + this.getWidth() < actor.getX() + actor.getWidth())) || ((this.getX() > actor.getX()) && (this.getX() < actor.getX() + actor.getWidth())))
		{
			if (this.getY() == actor.getY())
			{
				return true;
			}
		}
		return false;
	}

	@Override
	public boolean collideRight(GameObject actor)
	{
		if ((this.getX() + this.getWidth() > actor.getX()) && (this.getX() + this.getWidth() < actor.getX() + actor.getWidth()))
		{
			if (this.getY() == actor.getY())
			{
				return true;
			}
		}
		return false;
	}

	@Override
	public boolean collideLeft(GameObject actor)
	{
		if ((this.getX() > actor.getX()) && (this.getX() < actor.getX() + actor.getWidth()))
		{
			if (this.getY() == actor.getY())
			{
				return true;
			}
		}
		return false;
	}
}
